#ifndef __CLIENT_TRANSFER__
#define __CLIENT_TRANSFER__

#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

#define BOOST_DATE_TIME_SOURCE

#include <boost/date_time/posix_time/posix_time.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/objdetect/objdetect.hpp>

using namespace boost;

#include <iostream>
#include <string>

#include <vector>
#include <algorithm>
#include <fstream>
#include <list>
using namespace std;

#include "ClientSock.h"
//for protobuf
#include "Image.pb.h"

using namespace Image::protobuf;

const int BUFFSIZE = 128;
typedef struct
{
    uint8_t *pBuff;         //图像Buff指针
    unsigned int MAXlength; //Buff总的大小
    unsigned int high;
    unsigned int width;
    unsigned int channels; //通道数

} image_buff;

#define MAX_BUFF_SIZE 1024 * 1024 * 3
#define MAX_BUFF_NUMBER 4

class CClientTransfer
{
public:
    CClientTransfer(const char *, const char *, const char *);
    virtual ~CClientTransfer(void);

    void StartThread(void);
    void WaitThreadTerminate(void);

private:
    int ucharToMat(const uint8_t *p2, cv::Mat &src, int flag);
    bool GetJpegData(image_buff &ImageInfo, std::string jpgPath);
    bool scanFilesUseRecursive(const string &rootPath, vector<string> &container = *(new vector<string>()));

    static void ReadJpegThread(void *arg);
    void ReadJpegData(void);
    boost::thread m_ReadThread; //读Jpeg线程

    //
    static void SendJpegThread(void *arg);
    void SendJpegData(void);
    boost::thread m_SendThread; //发送Jpeg图片

    std::string m_jpgPath;
    vector<string> m_vecFilePic; //jpeg目录
    unsigned int m_PicId;        //jpeg vector 容器中的第几张图片
	    unsigned int m_coutSend;

    //图像Buff 空List
    list<image_buff> IdleList;
    //发送图像Buff List
    list<image_buff> SendBuffList;
    bool m_readQuit;; //线程结束标志
	bool    m_sendQuit;

    //多线程同步
    typedef boost::try_mutex MUTEX;
    typedef MUTEX::scoped_try_lock LOCK;
    MUTEX iomutex;

    //asio
    CClientSock *m_sock;
};

#endif
